package com.tanhua.manage.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.tanhua.manage.domain.Log;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

public interface LogMapper extends BaseMapper<Log> {

    /**
     * 查询新注册用户、登陆次数
     */
    @Select("SELECT COUNT(DISTINCT user_id) FROM tb_log " +
            "WHERE TYPE=#{type} AND log_time=#{now} ")
    Long queryNumsByType(@Param("type") String type, @Param("now") String now);

    /**
     * 查询活跃用户
     */
    @Select("SELECT COUNT(DISTINCT user_id) FROM tb_log WHERE log_time=#{now}")
    Long queryNumsByDate(String now);

    /**
     * 次日留存 （昨天注册，今天登陆）
     */
    @Select("SELECT COUNT(DISTINCT user_id) FROM tb_log " +
            "WHERE TYPE='0101' AND log_time=#{now} AND user_id IN (" +
            "SELECT user_id FROM tb_log WHERE TYPE='0102' AND log_time=#{yes})")
    Long queryNumRetention1d(@Param("now") String now, @Param("yes") String yes);
}
